package com.JFapp.controller;

import com.JFapp.domain.dto.*;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.domain.entity.User;
import com.JFapp.service.UserService;
import com.JFapp.utils.BeanCopyUtils;
import com.JFapp.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/user")
@Api("后台人员管理")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("查询所有人员")
    @GetMapping("/list")
    public ResponseResult getAllUser(Integer pageNum,Integer pageSize){
        return userService.selectAllUser(pageNum,pageSize);
    }

    @ApiOperation("查询人员详细")
    @GetMapping("/{userId}")
    public ResponseResult getUserDetail(@PathVariable Long userId){
        return userService.getUserDetail(userId);
    }

    @ApiOperation("修改用户状态")
    @PutMapping("/changeStatus")
    @PreAuthorize("@ps.hasPermission('system:user:edit')")
    public ResponseResult changeUserStatus(@RequestBody ChangeUserStatusDto changeUserStatusDto){
        return userService.changeUserStatus(changeUserStatusDto);
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/{userId}")
    @PreAuthorize("@ps.hasPermission('ssystem:user:remove')")
    public ResponseResult deleteUser(@PathVariable Long userId){
        userService.getBaseMapper().deleteById(userId);
        return ResponseResult.okResult();
    }


    @ApiOperation("更新用户信息")
    @PutMapping()
    public ResponseResult updateUser(@RequestBody UserDetailDto userDetailDto){
        return userService.updateUser(userDetailDto);
    }

    @ApiOperation("模糊查询用户")
    @GetMapping("/getUserByFuzzy")
    public ResponseResult getUserByFuzzy( UserByFuzzyDto userDetailDto){
        return  userService.getUserByFuzzy(userDetailDto);
    }

    @ApiOperation("获取用户id")
    @GetMapping("/getUserId")
    public ResponseResult getUserId(){
        return ResponseResult.okResult(SecurityUtils.getUserId());
    }
//    @ApiOperation("重置密码")
//    @PutMapping("/resetPwd")
//    public ResponseResult resetPwdById(@RequestBody @Validated ResetPwdDto resetPwdDto){
//        return userService.resetPwdById(resetPwdDto);
//    }

}
